export default {
    name: 'WelcomePage',
    data() {
        return {
            name: '',
            ismanager: true,
            isrenshi: true,
            iscaiwu: true,
            isCollapse: true,
            activeIndex: '3',
            teamMembers: [
                '吴耀好', '吴文钦', '吕瑞峰',
                '吴皓然', '代程聪', '刘仁杰'
            ],
            repoUrl: 'https://gitee.com/wu-yaohao/attendance-system',
            contactQQ: '2517926599'
        };
    },
    computed: {
        welcomeTitle() {
            return `${this.name}，欢迎使用2022级教学班1217第一组的公司考勤管理系统`;
        },
        firstChar() {
            return this.name ? this.name.charAt(0) : '';
        }
    },
    created() {
        this.checkLoginStatus();
        this.checkUserRole();
    },
    methods: {
        checkLoginStatus() {
            if (!window.sessionStorage.getItem('empId')) {
                this.$router.replace({ path: '/login' });
            } else {
                this.name = window.sessionStorage.getItem('name');
                // 如果你不希望自动跳转到个人信息页，可以注释掉下一行
                // this.$router.push('/Mine/MyInfo');
            }
        },

        checkUserRole() {
            const role = window.sessionStorage.getItem('role');
            if (['0', '1', '2'].includes(role)) {
                this.ismanager = false;
                this.isrenshi = false;
                this.iscaiwu = false;
            }
        },

        handleCommand(command) {
            const commandHandlers = {
                logout: this.handleLogout,
                myInfo: this.navigateToMyInfo
            };

            if (commandHandlers[command]) {
                commandHandlers[command]();
            }
        },

        handleLogout() {
            window.sessionStorage.removeItem('empId');
            window.sessionStorage.removeItem('name');
            this.$router.replace({ path: '/login' });
        },

        navigateToMyInfo() {
            this.$router.replace({ path: '/Mine/MyInfo' });
        },

        handleOpen(key) {
            this.activeIndex = key;
        }
    }
};